package com.tencent.qcloud.tuikit.tuichat.zhiyu.bean;

import android.text.TextUtils;
import com.google.gson.Gson;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import com.ysg.utils.YStringUtil;

public class CustomZhiyuMessageBean extends TUIMessageBean {
    public CustomZhiyuMessage customMessage;
    private String data;

    @Override
    public String onGetDisplayString() {
        return getText();
    }

    @Override
    public void onProcessMessage(V2TIMMessage v2TIMMessage) {
        data = new String(v2TIMMessage.getCustomElem().getData());
        if (!TextUtils.isEmpty(data)) {
            try {
                customMessage = new Gson().fromJson(data, CustomZhiyuMessage.class);
            } catch (Exception e) {
                TUIChatLog.e("CustomLinkMessageBean", "exception e = " + e);
            }
        }
        if (customMessage != null) {
            setExtra(customMessage.text);
        }
    }

    public String getText() {
        if (customMessage != null) {
            if (YStringUtil.contains(data, "@@@@@***")) {
                return "[礼物消息]";
            } else if (YStringUtil.contains(data, "qbt")) {//丘比特消息
                if (YStringUtil.contains(data, "@@@@@**")) {
                    return "<font size='12' color='#E61c6c'><normal>" + "[回复得红包]" + "</normal></font>";
                } else {
                    return "[系统消息]";
                }
            } else if (YStringUtil.contains(data, "version")) {//连麦
                return "[连麦消息]";
            }else{
                return customMessage.text;
            }
        }
        return getExtra();
    }

    public String getType() {
        if (customMessage != null) {
            return customMessage.type;
        }
        return "";
    }

}
